clear all
set more off
	
global dir = "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"	

cd "$dir"

use "Data\cand_level_persist_rep.dta",clear	
		
	gen treat=0
	replace treat=1 if margin_victory>0&margin_victory~=.
	replace treat=. if margin_victory==.

	gen treat_margin_victory=treat*margin_victory
	gen margin_victory_sq=margin_victory^2
	gen treat_margin_victory_sq=treat*margin_victory_sq

	texdoc close 
	cap erase "$dir/Tables/TableF3.tex"
	texdoc init "$dir/Tables/TableF3.tex", force
	
	tex \begin{table}[tbph]
	tex \caption{Effect of donating to an election winner on future donations (candidate's family members vs. Non members global parametric quadratic RD)}\label{tab:donation_fam_nofam_l}
	tex \centering
	tex \begin{tabular}{l c c } \hline
	tex Outcome : & Any race & Mayor  \\ 
	tex & (1) & (2)  \\ \hline
	tex \multicolumn{2}{l}{Panel A: Candidates' family members}\\
	tex & &  \\
	
	*Model 1
	foreach x in donate_15any b5{
		

		
		quietly: regress f`x' treat treat_margin_victory_sq margin_victory_sq treat_margin_victory margin_victory, vce(cluster muni_code)

		quietly sum f`x' if e(sample)
			local fmean_`x' : di %5.3f r(mean)
			local fsd_`x' : di %5.3f r(sd) 		
		
		regress f`x' treat treat_margin_victory_sq margin_victory_sq treat_margin_victory margin_victory, vce(cluster muni_code)

		local fN_`x' : di %5.0f e(N)
		local fR2_`x' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local fb1_`x' : di %5.3f b[1,1]
		local fse1_`x' : di %5.3f sqrt(v[1,1])
		local fp_v_`x' :di %5.3f res[4,1]
		local fuci_`x': di %5.3f res[6,1]
		local flci_`x': di %5.3f res[5,1]

				
		*No Family
		*Regressions
		*Summary statistics for the mean
			quietly: regress nf`x' treat treat_margin_victory_sq margin_victory_sq treat_margin_victory margin_victory, vce(cluster muni_code)
			quietly sum nf`x' if e(sample)
			local nfmean_`x' : di %5.3f r(mean)
			local nfsd_`x' : di %5.3f r(sd) 		
		
		regress nf`x' treat treat_margin_victory_sq margin_victory_sq treat_margin_victory margin_victory, vce(cluster muni_code)

		local nfN_`x' : di %5.0f e(N)
		local nfR2_`x' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local nfb1_`x' : di %5.3f b[1,1]
		local nfse1_`x' : di %5.3f sqrt(v[1,1])
		local nfp_v_`x' :di %5.3f res[4,1]
		local nfuci_`x': di %5.3f res[6,1]
		local nflci_`x': di %5.3f res[5,1]
	}
	
	*Continue table
	tex Electoral victory & `fb1_donate_15any' & `fb1_b5'  \\
	tex \ \ \ \ p-value & `fp_v_donate_15any' & `fp_v_b5' \\
	tex \ \ \ \ CI 95\%  & [`flci_donate_15any',`fuci_donate_15any'] & [`flci_b5',`fuci_b5']  \\
	tex & &  \\
	
	tex Observations & `fN_donate_15any' & `fN_b5' \\
	tex Mean & `fmean_donate_15any' & `fmean_b5' \\
	tex R-squared & `fR2_donate_15any' & `fR2_b5'  \\ 
	
	tex & & \\ \hline
	tex {Panel B: Non-family members}&  \\  
	tex & &  \\

		tex Electoral victory & `nfb1_donate_15any' & `nfb1_b5'  \\
	tex \ \ \ \ p-value & `nfp_v_donate_15any' & `nfp_v_b5' \\
	tex \ \ \ \ CI 95\%  & [`nflci_donate_15any',`nfuci_donate_15any'] & [`nflci_b5',`nfuci_b5']  \\
	tex & &  \\
	
	tex Observations & `nfN_donate_15any' & `nfN_b5' \\
	tex Mean & `nfmean_donate_15any' & `nfmean_b5' \\ \hline
	tex \end{tabular}
	tex \parbox{160mm}{ \footnotesize{
	tex \footnotesize{OLS estimates of average treatment effects at the cutoff. Controls include the interaction of the treatment with running variable and running variable, interaction of the treatment with the squared running variable, and the running variable squared. P-values and 95\% robust confidence intervals with clustering at the municipality level.
	tex }
	tex }}
	tex \end{table}
	cap texdoc close 
	
	
